﻿

 
function BorrowerDto(serviceUrl)
{
	var serviceUrl = serviceUrl;
	
	this.id = undefined;
	this.isPrimary = undefined;
	this.firstName = undefined;
	this.middleName = undefined;
	this.lastName = undefined;
	this.suffix = undefined;
	this.ssn = undefined;
	this.phoneNumber = undefined;
	this.phoneType = undefined;
	this.dateOfBirth = undefined;
	this.maritalStatus = undefined;
	this.yearsOfSchool = undefined;
	this.isFirstTimeBuyer = undefined;
	this.totalMonthlyIncome = undefined;

	var dateTimeFields = [
		"dateOfBirth",
	];
	
	this.CreateBorrower = function(success, error, LOANNUMBER) {
		$.ajax({
				url: serviceUrl + "/" + "loans/" + LOANNUMBER + "/borrowers",
				type: "POST",
				dataType: "json",
				data: JSON.stringify(this),
				processData: false,
				contentType: "application/json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}
	
	this.UpdateBorrower = function(success, error, LOANNUMBER) {
		$.ajax({
				url: serviceUrl + "/" + "loans/" + LOANNUMBER + "/borrowers",
				type: "PUT",
				dataType: "json",
				data: JSON.stringify(this),
				processData: false,
				contentType: "application/json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}
	
	this.GetBorrower = function(success, error, LOANNUMBER, BORROWERID) {
		$.ajax({
				url: serviceUrl + "/" + "loans/" + LOANNUMBER + "/borrowers/" + BORROWERID + "",
				type: "GET",
				dataType: "json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}

	this.DeleteBorrower = function(success, error, LOANNUMBER, BORROWERID) {
		$.ajax({
				url: serviceUrl + "/" + "loans/" + LOANNUMBER + "/borrowers/" + BORROWERID + "",
				type: "DELETE",
				dataType: "json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}
}
 
function LoanDto(serviceUrl)
{
	var serviceUrl = serviceUrl;
	
	this.loanNumber = undefined;
	this.primaryBorrower = undefined;
	this.numberOfBorrowers = undefined;
	this.applicationDate = undefined;
	this.loanAmount = undefined;
	this.loanTermInYears = undefined;

	var dateTimeFields = [
		"applicationDate",
	];
	
	this.CreateLoan = function(success, error) {
		$.ajax({
				url: serviceUrl + "/" + "loans/",
				type: "POST",
				dataType: "json",
				data: JSON.stringify(this),
				processData: false,
				contentType: "application/json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}
	
	this.UpdateLoan = function(success, error) {
		$.ajax({
				url: serviceUrl + "/" + "loans/",
				type: "PUT",
				dataType: "json",
				data: JSON.stringify(this),
				processData: false,
				contentType: "application/json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}
	
	this.GetLoan = function(success, error, LOANNUMBER) {
		$.ajax({
				url: serviceUrl + "/" + "loans/" + LOANNUMBER + "",
				type: "GET",
				dataType: "json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}

	this.DeleteLoan = function(success, error, LOANNUMBER) {
		$.ajax({
				url: serviceUrl + "/" + "loans/" + LOANNUMBER + "",
				type: "DELETE",
				dataType: "json",
				cache: false,
				success: success,
				error: error,
				dataFilter: function(data, type) {
						return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, "new $1");
					}});
	}
}
